#pragma once

#include "../common.h"
#include "../helpers/DString.h"
#include "../SexyThread.h"

namespace DeepClasses
{

	class DCreature;

	enum DTASKS {DTASK_unknown, DTASK_idle, DTASK_findpath, DTASK_act};
	class DTask
	{
	public:
		DTask();
		virtual ~DTask();

		DTASKS m_curTask;

		DTask* m_next;
		
		TLocation m_targetPoint;

		DCreature* m_owner;

		virtual int Tick();

	};

	class DTskIdle : public DTask
	{
	public:
		DTskIdle();
		virtual ~DTskIdle();

		virtual int Tick();
	};

	class DTskFindPath : public DTask
	{
	public:
		DTskFindPath();
		virtual ~DTskFindPath();

		virtual int Tick();
	private:
		enum FP_Mode {FP_Start, FP_Wait, FP_Walk};
		FP_Mode m_mode;
		SexyThread m_solver;
		bool m_stopSolver;
		static int SolverFunc(void* context);
		int TestCells(std::list<TLocationPath*>& openList,std::list<TLocationPath*>& closedList,TLocationPath* curloc);
		bool IsPassable(TLocationPath* loc);
		bool IsInList(std::list<TLocationPath*>& list, TLocationPath* loc);
		void AddToOpenList(std::list<TLocationPath*>& list, TLocationPath* loc, TLocationPath* curloc);
	};

	class DTskAct : public DTask
	{
	public:
		DTskAct();
		virtual ~DTskAct();
		
		virtual int Tick();
	};
};